﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IoTClient;
using IoTClient.Clients.PLC;
using IoTClient.Common.Enums;
using IoTClient.Enums;

namespace SprayProcessSCADASystem.Common
{
    public static class Global
    {
        public static IServiceProvider? Service { get; set; }

        public static IniFile IniFile { get; set; } = new IniFile(Application.StartupPath + "\\config.ini");


        #region PLC配置相关
        //西门子PLC客户端
        public static SiemensClient? SiemensClient { get; set; }
        public static string IpAddress { get; set; }
        public static int Port { get; set; }

        public static SiemensVersion CpuType{ get; set; }
        public static Byte Slot { get; set; }
        public static Byte Rack { get; set; }
        public static Int32 ConnectTimeOut { get; set; }
        public static Int32 ReadTimeInterval { get; set; }
        public static Int32 ReConnectTimeInterval { get; set; }
        public static string PlcVarConfigPath { get; set; }

        #endregion


        public static Dictionary<string,DataTypeEnum> ReadDic = new Dictionary<string, DataTypeEnum>();
        public static Dictionary<string, object> DataDic = new Dictionary<string, object>();
        public static Dictionary<string, string> WriteDic = new Dictionary<string, string>();

        public static bool PlcWrite(string varName,dynamic value)
        {
            string address = WriteDic[varName];
            if (SiemensClient == null || !SiemensClient.Connected) return false;
            Result result = SiemensClient?.Write(address, value) ;
            if (result == null || !result.IsSucceed) return false;
            return true;


        }

        public static string DelFilePath { get; set; }
        public static string SaveDay { get; set; }
        public static int SYTime { get; set; }
        public static string SoftwareVersion { get; set; }




    }
}
